home *** CD-ROM | disk | FTP | other *** search
/ Your Web Site Creator / Your Web Site Creator.iso / WebSite / data1.cab / Program_Executable_Files / Classes / FIRECAN2.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-13  |  4.2 KB  |  182 lines

  1. import java.applet.Applet;
  2. import java.awt.Canvas;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.util.Random;
  9.  
  10. public class FireworksCanvas2 extends Canvas implements Runnable {
  11.    Thread appThread;
  12.    Image osImage;
  13.    Graphics osg;
  14.    Color bkColor;
  15.    Image bkImage;
  16.    int rocketCount;
  17.    Random randomizer;
  18.    double[] radius;
  19.    int[] centerX;
  20.    int[] centerY;
  21.    double[] currRadius;
  22.    int newX;
  23.    int newY;
  24.    Color[] colors;
  25.    int[] colorIndex;
  26.    double[] cosines;
  27.    double[] sines;
  28.  
  29.    public FireworksCanvas2(Applet var1, int var2) {
  30.       this.GetParameters(var1, var2);
  31.       this.randomizer = new Random(System.currentTimeMillis());
  32.       this.colors = new Color[13];
  33.       this.colors[0] = Color.black;
  34.       this.colors[1] = Color.blue;
  35.       this.colors[2] = Color.cyan;
  36.       this.colors[3] = Color.darkGray;
  37.       this.colors[4] = Color.gray;
  38.       this.colors[5] = Color.green;
  39.       this.colors[6] = Color.lightGray;
  40.       this.colors[7] = Color.magenta;
  41.       this.colors[8] = Color.orange;
  42.       this.colors[9] = Color.pink;
  43.       this.colors[10] = Color.red;
  44.       this.colors[11] = Color.white;
  45.       this.colors[12] = Color.yellow;
  46.    }
  47.  
  48.    void GetParameters(Applet var1, int var2) {
  49.       String var3 = var1.getParameter("fireworksBkColor" + var2);
  50.       this.bkColor = AppletParam2.GetColor(var3, (Color)null);
  51.       if (this.bkColor != null) {
  52.          ((Component)this).setBackground(this.bkColor);
  53.       }
  54.  
  55.       var3 = var1.getParameter("fireworksBkImage" + var2);
  56.       this.bkImage = var1.getImage(var1.getCodeBase(), var3);
  57.    }
  58.  
  59.    public void Start() {
  60.       this.appThread = new Thread(this);
  61.       this.appThread.start();
  62.    }
  63.  
  64.    public void Stop() {
  65.       this.appThread.stop();
  66.       this.appThread = null;
  67.    }
  68.  
  69.    public void update(Graphics var1) {
  70.       if (this.osImage == null) {
  71.          this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  72.          this.osg = this.osImage.getGraphics();
  73.       }
  74.  
  75.       this.osg.setColor(((Component)this).getBackground());
  76.       this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  77.       if (this.bkImage != null) {
  78.          int var2 = this.bkImage.getWidth(this);
  79.          int var3 = this.bkImage.getHeight(this);
  80.          int var4 = ((Component)this).size().width / var2;
  81.          int var5 = ((Component)this).size().height / var3;
  82.          ++var4;
  83.          ++var5;
  84.  
  85.          for(int var6 = 0; var6 < var5; ++var6) {
  86.             for(int var7 = 0; var7 < var4; ++var7) {
  87.                this.osg.drawImage(this.bkImage, var7 * var2, var6 * var3, this);
  88.             }
  89.          }
  90.       }
  91.  
  92.       for(int var8 = 0; var8 < this.rocketCount; ++var8) {
  93.          this.osg.setColor(this.colors[this.colorIndex[var8]]);
  94.  
  95.          for(int var9 = 0; var9 < 16; ++var9) {
  96.             for(double var11 = this.currRadius[var8]; var11 > this.currRadius[var8] - (double)10.0F; var11 -= (double)2.0F) {
  97.                if (var11 > (double)0.0F) {
  98.                   this.newX = this.centerX[var8] + (int)(this.cosines[var9] * var11);
  99.                   this.newY = this.centerY[var8] + (int)(this.sines[var9] * var11);
  100.                   this.osg.drawLine(this.newX, this.newY, this.newX, this.newY);
  101.                }
  102.             }
  103.          }
  104.       }
  105.  
  106.       var1.drawImage(this.osImage, 0, 0, this);
  107.    }
  108.  
  109.    public void run() {
  110.       while(true) {
  111.          try {
  112.             ((Component)this).repaint();
  113.             this.UpdateRockets();
  114.             Thread.sleep(100L);
  115.          } catch (InterruptedException var1) {
  116.          }
  117.       }
  118.    }
  119.  
  120.    public Dimension minimumSize() {
  121.       return new Dimension(10, 10);
  122.    }
  123.  
  124.    public Dimension preferredSize() {
  125.       return new Dimension(10, 10);
  126.    }
  127.  
  128.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  129.       super.reshape(var1, var2, var3, var4);
  130.       this.osImage = null;
  131.       this.osg = null;
  132.       this.Initialize();
  133.    }
  134.  
  135.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  136.       ((Component)this).repaint();
  137.       return true;
  138.    }
  139.  
  140.    void Initialize() {
  141.       this.rocketCount = Math.max(Math.abs(this.randomizer.nextInt()) % 10, 3);
  142.       this.radius = new double[this.rocketCount];
  143.       this.centerX = new int[this.rocketCount];
  144.       this.centerY = new int[this.rocketCount];
  145.       this.currRadius = new double[this.rocketCount];
  146.       this.colorIndex = new int[this.rocketCount];
  147.  
  148.       for(int var1 = 0; var1 < this.rocketCount; ++var1) {
  149.          this.centerX[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().width - 20);
  150.          this.centerY[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().height - 20);
  151.          this.radius[var1] = (double)Math.max(30, Math.abs(this.randomizer.nextInt()) % 200);
  152.          this.currRadius[var1] = (double)0.0F;
  153.          this.colorIndex[var1] = Math.abs(this.randomizer.nextInt()) % 12;
  154.       }
  155.  
  156.       int var2 = 0;
  157.       this.cosines = new double[16];
  158.       this.sines = new double[16];
  159.  
  160.       for(double var3 = (double)0.0F; var3 < (Math.PI * 2D); var3 += (Math.PI / 8D)) {
  161.          this.cosines[var2] = Math.cos(var3);
  162.          this.sines[var2] = Math.sin(var3);
  163.          ++var2;
  164.       }
  165.  
  166.    }
  167.  
  168.    void UpdateRockets() {
  169.       for(int var1 = 0; var1 < this.rocketCount; ++var1) {
  170.          int var10002 = this.currRadius[var1]++;
  171.          if (this.currRadius[var1] >= this.radius[var1]) {
  172.             this.centerX[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().width - 20);
  173.             this.centerY[var1] = Math.abs(this.randomizer.nextInt()) % (((Component)this).size().height - 20);
  174.             this.radius[var1] = (double)Math.max(30, Math.abs(this.randomizer.nextInt()) % 100);
  175.             this.currRadius[var1] = (double)0.0F;
  176.             this.colorIndex[var1] = Math.abs(this.randomizer.nextInt()) % 12;
  177.          }
  178.       }
  179.  
  180.    }
  181. }
  182.